import getApiData, { getNestApiData } from "../../../../../services/cpasRequest";
import { BatReplaceWpData } from "../../../typings"

/**
 * 获取一个组成部分的底稿年度列表
 * @param dbname 
 * @returns 
 */
export async function getDgndList(dbname: string) {
    const retData = await getApiData('sjdg.dgnd.list', { dbname });
    if (retData.ok && retData.data) {
        return retData.data.map((item: { dgnd: string; }) => item.dgnd);//['2017','2018']
    }
    return [];
}
//搜索路径中文件 
//FileTypeArray:    export const dgFileTypeArray = ['*.xls', '*.xlsx', '*.xlsm', '*.doc', '*.docx', '*.pdf', 
//'*.rar', '*.zip', '*.7z','*.jpg', '*.gif', '*.bmp'];
export async function getSearchFiles(filePath: string) {
    const retData = await getNestApiData('/draftManage/getFilesByFileType', 'POST',
        { filePath, fileTypeArray: [] });
    if (retData.ok && retData.data) {
        return retData.data.filter((fileName: string) =>
            !fileName.includes('__history\\') || fileName.includes('__history/'))//不要历史
    }
    return [];
}
/**
 * 
 * 获取用于替换的底稿列表
 * @param dbname 
 * @param dgnd 
 * @returns 
 */
export async function getBatReplaceWpDataList(dbname: string, dgnd: string): Promise<BatReplaceWpData[]> {
    const retData = await getApiData('sjdg.batReplace.list', { dbname, dgnd });
    if (retData.ok && retData.data) {
        return retData.data as BatReplaceWpData[];//['2017','2018']
    }
    return [];
}

export function getZoomScale(value: number) {
    return value * (window.innerWidth / 1366);
}

/**
 * 是否是数字
 * @param str 
 * @returns 
 */
export function isNumeric(str: any) {
    return !isNaN(str)/*  && !isNaN(parseFloat(str)) */;
}
